{extend name="layout:base" /}
{block name="page_style"}
  <link rel="stylesheet" href="{$site_root}/static/ace1.4/assets/css/bootstrap-datepicker3.css" />
{/block}
{block name="main_content"}
  <div class="page-content">
    <!--主题-->
    <?php if(!empty($current_page)): ?>
      <div class="page-header">
        <h1>
          您当前操作
          <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
            {$current_page.title|default=''}
          </small>
        </h1>
      </div>
    <?php endif; ?>
    <div class="row">
      <div class="col-xs-12">
        <form class="form-horizontal adminform" id="model-form" method="post" action="">
          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right"> 
              用户昵称：<span class="red">*</span>
            </label>
            <div class="col-sm-10">
              <input type="text" name="nickname" placeholder="请输入用户昵称" class="col-xs-10 col-sm-5" value="{$user.nickname|default=''}" autocomplete="off"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right"> 
              注册手机：<span class="red">*</span>
            </label>
            <div class="col-sm-10">
              <input type="text" name="mobile" placeholder="请输入用户的注册手机" class="col-xs-10 col-sm-5" value="{$user.mobile|default=''}" autocomplete="off" <?php if(isset($user['id'])){echo('readonly="readonly"');} ?> required/>
            </div>
          </div>
          <div class="space-4"></div>

          <?php if(isset($user['id'])): ?>
            <div class="form-group">
              <label class="col-sm-2 control-label no-padding-right"> 
                用户头像：
              </label>
              <div class="col-sm-10">
                
              </div>
            </div>
            <div class="space-4"></div>
          <?php else: ?>
            <div class="form-group">
              <label class="col-sm-2 control-label no-padding-right"> 
                登录密码：<span class="red">*</span>
              </label>
              <div class="col-sm-10">
                <input type="password" name="password_hide"  style="display:none"/> 
                <input type="password" id="password" name="password" placeholder="请输入用户的登录密码" class="col-xs-10 col-sm-5" value="" autocomplete="off" required/>
              </div>
            </div>
            <div class="space-4"></div>

            <div class="form-group">
              <label class="col-sm-2 control-label no-padding-right"> 
                再次输入密码：<span class="red">*</span>
              </label>
              <div class="col-sm-10">
                <input type="password" id="confirm_password" name="confirm_password" placeholder="请再次输入用户的登录密码" class="col-xs-10 col-sm-5" autocomplete="off" value="" required/>
              </div>
            </div>
            <div class="space-4"></div>
          <?php endif; ?>
          
          <!--
          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right"> 
              总积分：
            </label>
            <label class="col-sm-10 control-label" style="text-align: left;"> 
              {//$user.total_score|default='0'}
            </label>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right"> 
              可用积分：
            </label>
            <div class="col-sm-10">
              <input type="number" name="active_score" placeholder="请输入用户的可用积分" class="col-xs-10 col-sm-5" value="{//$user.active_score|default='0'}" autocomplete="off"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right"> 
              总元宝：
            </label>
            <label class="col-sm-10 control-label" style="text-align: left;"> 
              {//$user.total_coin|default='0'}
            </label>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right"> 
              可用元宝：
            </label>
            <div class="col-sm-10">
              <input type="number" name="active_coin" placeholder="请输入用户的可用元宝" class="col-xs-10 col-sm-5" value="{//$user.active_coin|default='0'}" autocomplete="off"/>
            </div>
          </div>
          <div class="space-4"></div>
          -->

          <div class="clearfix form-actions">
            <div class="col-md-offset-3 col-md-9">
              <?php if(isset($user['id'])): ?>
                <input type="hidden" name="id" id="id" value="{$user.id}">
              <?php endif; ?>
              <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                保存
              </button>

              &nbsp; &nbsp; &nbsp;
              <button class="btn" type="reset">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                重置
              </button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
{/block}
{block name="page_js"}
  <script src="{$site_root}/static/plugins/jquery-validate/jquery.validate.min.js"></script>
  <script type="text/javascript">
    var $form = $("form#model-form");
    $form.validate({
      rules:{
        "mobile":{
          required: true,
          min: 13000000000,
          max: 19900000000,
          remote: {
            url: "{:url('index/register/ajax_check_unique')}",
            type: "post",
            data: {
              field: "mobile",
              id: function(){
                var id = 0;
                if($form.find("input#id").length){
                  id = $form.find("input#id").val();
                }
                return id;
              }
            }
          }
        },"nickname":{
          required: true,
          minlength: 3,
          maxlength: 30
        },"active_score":{
          required: true,
          min: 0,
          max: 999999999
        },"active_coin":{
          required: true,
          min: 0,
          max: 999999999
        },"password":{
          minlength: 6,
          maxlength: 20
        },"confirm_password":{
          equalTo: "#password"
        }
      },
      messages:{
        "mobile":{
          required: "用户手机号码不能为空",
          min: "用户手机号码正确",
          max: "用户手机号码正确",
          remote: "用户手机号码已存在"
        },"nickname":{
          required: "请输入用户昵称",
          minlength: "用户昵称长度必须在3-30个字符之间",
          maxlength: "用户昵称长度必须在3-30个字符之间"
        },"active_score":{
          min: "用户的可用积分不能小于0",
          max: "用户的可用积分不能大于999999999"
        },"active_coin":{
          min: "用户的可用元宝不能小于0",
          max: "用户的可用元宝不能大于999999999"
        },"password":{
          minlength: "登录密码长度必须在6-20之间",
          maxlength: "登录密码长度必须在6-20之间"
        },"confirm_password":{
          equalTo: "两次输入的密码一致"
        }
      },
      errorClass: "help-inline input-error",
      errorElement: "span",
      highlight:function(element, errorClass, validClass) {
        $(element).parents('.form-group').addClass('has-error');
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).parents('.form-group').removeClass('has-error');
      },
      submitHandler: function(form){
        var $form = $(form);
        $.ajax({
          url: $form.attr("action"),
          type: $form.attr("method"),
          dataType: "JSON",
          data: $form.serialize(),
          success: function(data){
            if(data.code){
              location.href = data["url"];
            }else{
              alert(data["msg"]);
            }
          }, error: function () {
            alert("数据执行错误！");
          }
        });
      }
    });
  </script>
{/block}